<!--已办-->
<template>
  <div>
    <!-- <div class="base-content"> -->
    <el-table
      class="filter unsetborder"
      :class="{ 'show-filter': showFilterRow }"
      :data="dataList"
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55">
        <el-table-column type="selection"></el-table-column>
      </el-table-column>
      <el-table-column align="center" width="50">
        <template #header>
          <div class="filter-icon" title="筛选">
            <SvgIcon
              class-name="filter"
              icon-class="filter"
              @click="filterIconClick"
            />
          </div>
        </template>
        <el-table-column width="50"></el-table-column>
      </el-table-column>
      <el-table-column align="center" label="序号" width="50">
        <el-table-column align="center">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="委托单号">
        <el-table-column prop="orderNum">
          <template #header>
            <el-input
              v-if="showFilterRow"
              v-model="queryForm.orderNum"
              @keyup.enter.native="onQuery"
            ></el-input>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="单位名称">
        <el-table-column prop="customerName">
          <template #header>
            <el-input
              v-if="showFilterRow"
              v-model="queryForm.customerName"
              @keyup.enter.native="onQuery"
            ></el-input>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="样品名称">
        <el-table-column prop="sampleName">
          <template #header>
            <el-input
              v-if="showFilterRow"
              v-model="queryForm.sampleName"
              @keyup.enter.native="onQuery"
            ></el-input>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="折扣方式">
        <el-table-column prop="discountType">
          <template #header>
            <el-select
              v-if="showFilterRow"
              v-model="queryForm.discountTypeCode"
            >
              <el-option
                v-for="(item, index) in discountTypeCodeEnum"
                :key="index"
                :label="item.value"
                :value="item.key"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="最终价">
        <el-table-column>
          <template slot-scope="scope">
            {{ convertUnit(scope.row.finalPrice) }}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="状态">
        <el-table-column prop="pricelStatus">
          <template #header>
            <el-select
              v-if="showFilterRow"
              v-model="queryForm.pricelStatusCode"
            >
              <el-option
                v-for="(item, index) in entrustPricelStatusCodeEnum"
                :key="index"
                :label="item.value"
                :value="item.key"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作">
        <el-table-column width="140">
          <template #header>
            <div v-if="showFilterRow" class="search-operate">
              <el-link type="primary" @click="onQuery">搜索</el-link>
              <el-link @click="cancelForm">清空</el-link>
            </div>
          </template>

          <template slot-scope="scope">
            <div class="base-table-operation">
              <el-link
                size="mini"
                type="primary"
                @click="handleDetails(scope.row)"
                >详情</el-link
              >
              <!-- <el-link :disabled="scope.row.pricelStatusCode==3||scope.row.pricelStatusCode==2" size="mini" type="primary" @click="handleEdit(scope.row)"
              >修改</el-link
            > -->
              <!-- <el-link size="mini" type="danger" @click="handleDelete(scope.row)"
              >删除</el-link
            > -->
            </div>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
    <EntrustOrderPriceDialog
      ref="EntrustOrderPriceDialog"
      v-model="priceDialogVisible"
      :entrust-order-id.sync="entrustOrderId"
      :read-only.sync="readOnly"
      :edit-id.sync="editId"
      :sample-registration-id.sync="sampleRegistrationId"
      @closePriceDialog="closePriceDialog"
    />
  </div>
</template>

<script>
import { UpdateDeleteFlag } from "../../../api/EntrustManage/EntrustOrderPrice.js";
import EntrustOrderPriceDialog from "./EntrustOrderPriceDialog.vue";
export default {
  name: "EntrustOrderPriceFinishList",
  components: {
    EntrustOrderPriceDialog,
  },
  props: {
    dataList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      discountTypeCodeEnum: [{
        key: -1,
        value: "全部"
      },
      {
        key: 0,
        value: "默认"
      },
      {
        key: 1,
        value: "检测项目协议价"
      },
      {
        key: 2,
        value: "整单折扣"
      }
      ],
      entrustPricelStatusCodeEnum: [{
        key: 0,
        value: "全部"
      },
      {
        key: 2,
        value: "核算中"
      },
      {
        key: 3,
        value: "已核算"
      }],
      showFilterRow: false,
      queryForm: {
        discountTypeCode: -1,
        pricelStatusCode: 0,
        orderNum: '',
        customerName: '',
        sampleName: ''
      },
      sampleRegistrationId: "",
      tableDatas: [],
      readOnly: false,
      priceDialogVisible: false,
      list: [],

      entrustOrderId: "",
      editId: "",
      formData: {
        id: 0,
        entrustOrderId: 0,
        customerId: 0,
        detectionPrice: 0,
        discountTypeCode: 0,
        agreementPrice: 0,
        discount: 0,
        favorablePrice: 0,
        finalPrice: 0,
        pricelStatusCode: 0,
        workFlowId: 0,
        approvalStatusCode: 0,
      },
      dialogFormVisible: false,
    };
  },
  created() { },
  methods: {
    onQuery() {
      this.$emit("updateQueryForm", this.queryForm);
    },

    filterIconClick() {
      this.showFilterRow = !this.showFilterRow;
      !this.showFilterRow && this.cancelForm();
    },
    // 清空筛选条件
    cancelForm() {
      this.queryForm = this.$options.data().queryForm;
      this.$emit("updateQueryForm", this.queryForm);
    },
    handleSelectionChange(val) {
      this.tableDatas = val;
    },
    // 修改
    handleEdit(row) {
      this.editId = row.id;
      this.entrustOrderId = row.entrustOrderId;
      this.priceDialogVisible = true;
    },
    // 转化单位分化元
    convertUnit(price) {
      return price / 100;
    },
    // 操作失败回调用
    faildfulOperation() {
      this.$message({
        type: "info",
        message: "已取消",
      });
    },
    closePriceDialog() {
      this.editId = "";
      this.priceDialogVisible = false;
      this.readOnly = false;
    },
    // 详情
    handleDetails(row) {
      this.readOnly = true;
      this.editId = row.id;
      this.sampleRegistrationId = row.sampleRegistrationId;
      this.entrustOrderId = row.entrustOrderId;
      this.priceDialogVisible = true;
    },
    handleDelete(rowData) {
      // 删除（修改删除状态）
      this.formData.id = rowData.id;
      this.$confirm("此操作将取消价格核算, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        callback: (action) => {
          if (action === "confirm") {
            UpdateDeleteFlag(this.formData)
              .then((res) => {
                this.$$parent.getdataList();
              })
              .catch((res) => {
                this.faildfulOperation();
              });
          }
        },
      });
    },
  },
};
</script>
